<?php

/**
 * This file is part of the Codizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Codizer Core Team <team@codizer.org>
 * @package     Codizer
 */

class f_file_Content extends f_file_File
{
	private $content;
	
	/**
	 * @param string $file
	 */
	function __construct($file)
	{
		if(file_exists(realpath($file)))
		{
			$this->file = realpath($file);
		}
		$this->getFileProperties($file);
		return $this;
	}
	
	/**
	 * @param string $file
	 * @return f_file_File
	 */
	public static function getInstance($file)
	{
		$className = __CLASS__;
		return new $className($file);
	}
	
	/**
	 * Retrieve file content and return the number of line retrieved
	 * @param integer $length
	 * @return integer
	 */
	public function retrieveContent($length=1024)
	{
		$i_c=0;
		$file_h = fopen($this->getFile(),"r");
		
		if($file_h === FALSE)
		{
			return -1; //got a problem
		}
		
		while(feof($file_h) === FALSE)
		{
			$this->content[]= fgets($file_h,$length);
			$i_c++;
		}
		fclose($file_h);
		
		return $i_c;
	}
	
	/**
	 * Get file content
	 *
	 * @return array<String>
	 */
	public function getContent()
	{
		return $this->content;
	}
}
?>